package io.renren.modules.yckj.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.yckj.dao.ProjectMachineDao;
import io.renren.modules.yckj.dto.ProjectMachineDTO;
import io.renren.modules.yckj.entity.ProjectMachineEntity;
import io.renren.modules.yckj.service.ProjectMachineService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 项目机器关系表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2025-04-24
 */
@Service
public class ProjectMachineServiceImpl extends CrudServiceImpl<ProjectMachineDao, ProjectMachineEntity, ProjectMachineDTO> implements ProjectMachineService {

    @Override
    public QueryWrapper<ProjectMachineEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");
        Object projectId = params.get("projectId");
        Object machineId = params.get("machineId");

        QueryWrapper<ProjectMachineEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
        wrapper.eq(ObjectUtil.isAllNotEmpty(projectId), "project_id", projectId);
        wrapper.eq(ObjectUtil.isAllNotEmpty(machineId), "machine_id", machineId);

        return wrapper;
    }


    @Override
    public List<ProjectMachineDTO> list(Map<String, Object> params) {
        List<ProjectMachineEntity> entityList = baseDao.selectList(this.getWrapper(params));
        return ConvertUtils.sourceToTarget(entityList, ProjectMachineDTO.class);
    }

    @Override
    public List<ProjectMachineDTO> getProjectMachineList(Map<String, Object> params) {
        List<ProjectMachineEntity> projectMachineList = baseDao.getProjectMachineList(params);
        return ConvertUtils.sourceToTarget(projectMachineList, ProjectMachineDTO.class);
    }
}